﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace theguineasyndrome
{
    abstract public class Splash
    {
        private Vector2 position;
        private Vector2 relativePosition;
        private Texture2D texture;
        private Rectangle rectangle;
        private ObstacleElement obstacleElement;
        private Color color;

        abstract public void applyEffect(GameTime gameTime, Character character);

        public Splash(Texture2D texture, Vector2 position)
        {
            this.texture = texture;
            this.position = position;
            this.color = Color.White;
            updateRectangle();
        }

        private void updateRectangle()
        {
            rectangle = new Rectangle((int)(position.X - texture.Width / 2), (int)(position.Y - texture.Height / 2), texture.Width, texture.Height);
        }

        public void setObstacle(ObstacleElement obstacleElement)
        {
            this.obstacleElement = obstacleElement;
            relativePosition = position - obstacleElement.Position;
        }

        public void setColor(Color color)
        {
            this.color = color;
        }

        public float Left
        {
            get { return position.X - texture.Width / 2; }
        }

        public float Right
        {
            get { return position.X + texture.Width / 2; }
        }

        public float CenterX
        {
            get { return position.X; }
        }

        public void Draw(SpriteBatch spriteBatch, Camera camera)
        {
            if (camera.isVisible(rectangle))
                spriteBatch.Draw(texture, camera.getDstRect(rectangle), color);
        }

        public void updatePosition()
        {
            position = obstacleElement.Position + relativePosition;
            updateRectangle();
        }
    }
}
